package com.lanhao.aot.excel;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.FileUtils;

import cn.hutool.core.io.FileUtil;

public class TxtUtil {
	public static final String FILE_ALL = "D:/file/合并版.txt";
	public static final String FILE_OFFLINE = "D:/file/原始版-离线.txt";
	public static final String FILE_ONLINE = "D:/file/原始版-在线.txt";
	
	
	public static void main(String[] args) {
		// 读取集合
		List<String> fileAll = FileUtil.readLines(new File(FILE_ALL), "UTF-8");
		
		Set<String> fileAllSet = new HashSet<String>(fileAll);
		System.out.println("全部数据size=" + fileAllSet.size());
		
		List<String> offlineAll = FileUtil.readLines(new File(FILE_OFFLINE), "UTF-8");
		
		System.out.println("离线全部数据size=" + offlineAll.size());
		
		List<String> offlineNew = new ArrayList<>();
		List<String> offlineNoNew = new ArrayList<>();
		
		for (String o : offlineAll) {
			if (fileAllSet.contains(o)) {
				offlineNew.add(o);
			} else {
				offlineNoNew.add(o);
			}
		}
		
		System.out.println("过滤后离线还剩下数据size=" + offlineNew.size());
		System.out.println("过滤后离线未匹配数据size=" + offlineNoNew.size());
		
		try {
			FileUtils.writeLines(new File("D:/file/处理版本-离线.txt"), offlineNew);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			FileUtils.writeLines(new File("D:/file/处理版本-离线-未匹配.txt"), offlineNoNew);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
		List<String> onlineAll = FileUtil.readLines(new File(FILE_ONLINE), "UTF-8");
		
		System.out.println("在线全部数据size=" + onlineAll.size());
		
		List<String> onlineNew = new ArrayList<>();
		List<String> onlineNoNew = new ArrayList<>();
		
		for (String o : onlineAll) {
			if (fileAllSet.contains(o)) {
				onlineNew.add(o);
			} else {
				onlineNoNew.add(o);
			}
			
		}
		
		System.out.println("过滤后在线还剩下数据size=" + onlineNew.size());
		System.out.println("过滤后在线未匹配数据size=" + onlineNoNew.size());
		
		try {
			FileUtils.writeLines(new File("D:/file/处理版本-在线.txt"), onlineNew);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			FileUtils.writeLines(new File("D:/file/处理版本-在线-未匹配.txt"), onlineNoNew);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
